import vue from "vue"
import vuex from "vuex"

vue.use(vuex);

const state = {
    count : 0
}
const mutations={
    add(state,n){
        state.count += n;
    },
    reduce(state,n){
        state.count -= n;
    }
}
const getters={
    count(state){
        return state.count += 20;
    }
}
const actions={
    addActions(context){
        context.commit("add",5);
        setTimeout(()=>{
            context.commit('reduce',1);
        },3000)
    },
    reduceActions({commit}){
        commit('reduce',4);
    }
}

const modulesA = {
    state,mutations,getters,actions
}

export default new vuex.Store({
    // state,mutations,getters,actions
    modules:{
        a:modulesA
    }
});